#include <iostream>

using namespace std;

class CountSort {
public:
    static void countSort(int *array, int length) {
        int minValue;
        int maxValue;

        bool flag = true;
        for (int i = 0; i < length; ++i) {
            int value = array[i];
            if (flag) {
                minValue = maxValue = value;
                flag = false;
            } else {
                minValue = min(minValue, value);
                maxValue = max(maxValue, value);
            }
        }

        cout << "minValue = " << minValue << endl;
        cout << "maxValue = " << maxValue << endl;

        int *temp = (int *) malloc(sizeof(int) * (maxValue - minValue + 1));
        for (int i = 0; i < length; ++i) {
            temp[array[i] - minValue]++;
        }

        int count = 0;
        for (int i = minValue; i <= maxValue; i++) {
            for (int j = 0; j < temp[i - minValue]; ++j) {
                array[count++] = i;
            }
        }

        free(temp);
    }
};